package cn.edu.ctbu.controller.user;

import cn.edu.ctbu.DTO.PutUserDTO.PutUserDTO;
import cn.edu.ctbu.VO.UserVO;
import cn.edu.ctbu.entity.User;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("用户端登录")
@RequestMapping("/user/user")
@Api(tags = "用户登录接口")
public class UserController {
    @Autowired
    IUserService iUserService;

    /**
     * 登录
     */
    @GetMapping("/login")
    @ApiOperation("用户登录")
    public Result<UserVO> login(String code){
        UserVO vo=iUserService.login(code);
        return Result.success(vo);
    }

    /**
     * 获得用户信息
     */
    @GetMapping
    @ApiOperation("获得用户信息")
    public Result<User> get(){
        User user=iUserService.get();
        return Result.success(user);
    }

    /**
     * 修改个人信息
     */
    @PutMapping
    public Result putUser(@RequestBody PutUserDTO dto){
        iUserService.putUser(dto);
        return Result.success();
    }
}
